#!/usr/bin/env python  
import RPi.GPIO as GPIO
import time
import atexit

def opengar(daolaji):      #open the corresponding trash
    # 0,1,2,3-----chuyu,kehui,qita,youhai
    if daolaji==0:
        atexit.register(GPIO.cleanup)  

        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(33, GPIO.OUT, initial=True)
        p = GPIO.PWM(33,50) #50HZ
        p.start(100)
        for i in range(0,120,10):
            p.ChangeDutyCycle(10 * i / 180)
            time.sleep(0.02)
            p.ChangeDutyCycle(0)
            time.sleep(0.2)
        time.sleep(2)
        for i in range(120,0,-10):
            p.ChangeDutyCycle(10 * i / 180)
            time.sleep(0.02) 
            p.ChangeDutyCycle(0)
            time.sleep(0.2)

    if daolaji==1:
        atexit.register(GPIO.cleanup)  

        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(12, GPIO.OUT, initial=True)
        p = GPIO.PWM(12,50) #50HZ
        p.start(100)
        for i in range(0,120,10):
            p.ChangeDutyCycle(10 * i / 180)
            time.sleep(0.02)
            p.ChangeDutyCycle(0)
            time.sleep(0.2)
        time.sleep(2)
        for i in range(120,0,-10):
            p.ChangeDutyCycle(10 * i / 180)
            time.sleep(0.02) 
            p.ChangeDutyCycle(0)
            time.sleep(0.2)
    if daolaji==2:
        atexit.register(GPIO.cleanup)  

        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(35, GPIO.OUT, initial=True)
        p = GPIO.PWM(35,50) #50HZ
        p.start(0)
        for i in range(120,0,-10):
            p.ChangeDutyCycle(10 * i / 180)
            time.sleep(0.02) 
            p.ChangeDutyCycle(0)
            time.sleep(0.2)
        time.sleep(2)
        for i in range(0,120,10):
            p.ChangeDutyCycle(10 * i / 180)
            time.sleep(0.02)
            p.ChangeDutyCycle(0)
            time.sleep(0.2)
    if daolaji==3:
        atexit.register(GPIO.cleanup)  

        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(37, GPIO.OUT, initial=True)
        p = GPIO.PWM(37,50) #50HZ
        p.start(50)
        for i in range(150,20,-10):
            p.ChangeDutyCycle(10 * i / 180)
            time.sleep(0.02) 
            p.ChangeDutyCycle(0)
            time.sleep(0.2)
        time.sleep(2)
        for i in range(20,150,10):
            p.ChangeDutyCycle(10 * i / 180)
            time.sleep(0.02)
            p.ChangeDutyCycle(0)
            time.sleep(0.2)

# # while 
# daolaji(0)
# daolaji(1)
# daolaji(2)
# daolaji(3)